using System;
using System.Collections.Generic;
using System.Text;
using GraphAlgsPresentation.Core;
using System.Xml.Serialization;
using System.ComponentModel;

namespace GraphAlgsPresentation.ScriptLibrary
{
    /// <summary>
    /// Provides a change vertex label
    /// </summary>
    [Serializable]
    public class ChangeVertexLabel : Command
    {
        private string name;
        private string newLabel;
        private string oldLabel;

        /// <summary>
        /// Gets or sets the old label.
        /// </summary>
        /// <value>The old label.</value>
        [XmlIgnore]
        [Browsable(false)]
        public String OldLabel
        {
            get { return oldLabel; }
            set { oldLabel = value; }
        }
        /// <summary>
        /// returns vertex's name
        /// </summary>
        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        /// <summary>
        /// returns new vertex's label
        /// </summary>
        public string NewLabel
        {
            get { return newLabel; }
            set { newLabel = value; }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ChangeVertexLabel"/> class.
        /// </summary>
        /// <param name="_name">Vertex's name</param>
        /// <param name="label">New vertex's label</param>
        /// <param name="effect">The effect.</param>
        public ChangeVertexLabel(string _name, string label, DrawEffect effect)
        {
            name = _name;
            newLabel = label;
            Effect = effect;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ChangeVertexLabel"/> class.
        /// </summary>
        /// <param name="id">The vertex's id.</param>
        /// <param name="label">The label.</param>
        /// <param name="effect">The effect.</param>
        public ChangeVertexLabel(int id, string label, DrawEffect effect)
        {
            name = (id + 1).ToString();
            newLabel = label;
            Effect = effect;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ChangeVertexLabel"/> class.
        /// </summary>
        public ChangeVertexLabel()
        {
        }

        /// <summary>
        /// Runs this instance.
        /// </summary>
        public override void Run()
        {
            LCVertex v = this.Context.GetVertex(name);
            oldLabel = v.Label;
            v.Label = newLabel;
            v.Updated = true;
            //this.Context.Layout.ReDraw();
        }

        /// <summary>
        /// Undoes this instance.
        /// </summary>
        public override void Undo()
        {
            LCVertex v = this.Context.GetVertex(name);
            v.Label = oldLabel;
            v.Updated = true;
            //this.Context.Layout.ReDraw();
        }
    }
}
